package com.xtx.air.common;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * 时间计算工具类
 * 
 * @author lenic
 * 
 */
public final class XtxDateUtils {

	private static Log logger = LogFactory.getLog(XtxDateUtils.class);

	private static final SimpleDateFormat BOARD_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");

	/**
	 * 检查字符串是否为登记日期格式
	 * 
	 * @param boardDate
	 * @return true=格式正确，false=格式不正确
	 */
	public static boolean checkBoardDate(String boardDate) {
		return boardDate.indexOf("-") != boardDate.lastIndexOf("-") && getBoardDate(boardDate) != null;
	}

	/**
	 * 获取登机日期的字符串
	 * 
	 * @param date
	 * @return yyyy-MM-dd
	 */
	public static String getBoardDate(Date date) {
		return BOARD_DATE_FORMAT.format(date);
	}

	/**
	 * 获取登记日期的java.util.Date对象
	 * 
	 * @param boardDate登机日期
	 *            (格式：yyyy-MM-dd)
	 * @return
	 */
	public static Date getBoardDate(String boardDate) {
		try {
			return BOARD_DATE_FORMAT.parse(boardDate);
		} catch (ParseException e) {
			logger.error("获取登机日期java.util.Date对象失败", e);
			return null;
		}
	}

	/**
	 * 计算登记日期的下一天
	 * 
	 * @param boardDate登机日期
	 *            (格式：yyyy-MM-dd)
	 * @return yyyy-MM-dd
	 */
	public static String nextBoardDate(String boardDate) {
		Date boardDateToUse = getBoardDate(boardDate);
		Calendar cal = Calendar.getInstance();
		cal.setTime(boardDateToUse);
		cal.add(Calendar.DATE, 1);
		return getBoardDate(cal.getTime());
	}

	/**
	 * _i_i_i_i_i_i_i_i_i_
	 * 
	 * @param i_i_i_i_i_i_i_i_
	 * @param _i_i_i_i_i_i_i_i_
	 * @param _i_i_i_i_i_i_i_i_
	 * @return i_i_i_i_i_i_i_i_
	 */
	public static int _i_(int i_i, int _, int _i_) {
		return (i_i > _ ? (i_i > _i_ ? i_i : _i_) : (_ > _i_ ? _ : _i_));
	}
}